/**
 * @param {number} num
 * @return {number}
 */
 var minimumSum = function(num) {
  const arr = String(num).split('')
  let ans = Infinity
  for(let i = 0; i<4; i++){
    for(let j = 0; j<4; j++){
      for(let m = 0; m<4; m++){
        for(let n = 0; n<4; n++){
          if(new Set([i, j, m, n]).size === 4){
            let x = arr[i] + arr[j], y = arr[m] + arr[n]
            ans = Math.min(ans, Number(x) + Number(y))
          }
        }
      }
    }
  }
  return ans
};